﻿package mortal.game.view.forging.renderer
{
    import com.mui.controls.*;
    import com.mui.utils.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.forging.data.*;
    import mortal.game.view.forging.view.*;
    import mortal.mvc.core.*;

    public class EquipDecomposePackCellRenderer extends GCellRenderer
    {
        private var _item:DecomposePackItem;
        private var _decomposeBackPackData:DecomposeBackPackData;

        public function EquipDecomposePackCellRenderer()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._item = UICompomentPool.getUICompoment(DecomposePackItem);
            this._item.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            this.addChild(this._item);
            this.addListeners();
            return;
        }// end function

        private function addListeners() : void
        {
            Dispatcher.addEventListener(EventName.ForgingAddDecomposeItem, this.onAddItemHandler);
            Dispatcher.addEventListener(EventName.ForgingCancelAddDecomposeItem, this.onCancelAddItemHandler);
            Dispatcher.addEventListener(EventName.ForgingAutoSelDecomposeItem, this.onAutoSelHandler);
            return;
        }// end function

        private function removeListeners() : void
        {
            Dispatcher.removeEventListener(EventName.ForgingAddDecomposeItem, this.onAddItemHandler);
            Dispatcher.removeEventListener(EventName.ForgingCancelAddDecomposeItem, this.onCancelAddItemHandler);
            Dispatcher.removeEventListener(EventName.ForgingAutoSelDecomposeItem, this.onAutoSelHandler);
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._decomposeBackPackData = param1 as DecomposeBackPackData;
            if (this._decomposeBackPackData != null)
            {
                this._item.itemData = this._decomposeBackPackData.itemData;
                this._item.canNotUse = this._decomposeBackPackData.isDisabled;
                this._item.mouseEnabled = !this._decomposeBackPackData.isDisabled;
                this._item.isBind = this._decomposeBackPackData.isBind;
                if (this._decomposeBackPackData.isNeedShowStrenLv)
                {
                    this._item.updateStrengLevel();
                }
                else
                {
                    this._item.clearStrengLevel();
                }
            }
            else
            {
                this._item.itemData = null;
                this._item.canNotUse = false;
                this._item.mouseEnabled = false;
                this._item.clearStrengLevel();
            }
            return;
        }// end function

        private function onAddItemHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            if (_loc_2 && this._item.itemData && _loc_2.uid == this._item.itemData.uid)
            {
                this._item.canNotUse = true;
                Cache.instance.forging.addDecomposeItem(_loc_2);
            }
            return;
        }// end function

        private function onCancelAddItemHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as ItemData;
            if (_loc_2 && this._item.itemData && _loc_2.uid == this._item.itemData.uid)
            {
                this._item.canNotUse = false;
            }
            return;
        }// end function

        private function onAutoSelHandler(event:DataEvent) : void
        {
            if (Cache.instance.forging.hasDecomposeItem(this._item.itemData))
            {
                this._item.canNotUse = true;
            }
            else
            {
                this._item.canNotUse = false;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._item.dispose(param1);
            this._item = null;
            this._decomposeBackPackData = null;
            this.removeListeners();
            return;
        }// end function

    }
}
